<template>
    <view class="bg-content">
        <u-search placeholder="请输入搜索关键词" shape="square" v-model="searchKeyword" @search="onSearch" @custom="onSearch"></u-search>
        <div style="background-color: white; padding: 15px 10px; border-bottom: 1px solid #eeeeee;"
             v-for="(tbCommunityDynamic, index) in tbCommunityDynamicList" :key="tbCommunityDynamic.id"
             @click="select(tbCommunityDynamic)">
            <div style="display: flex;">
                <div style="width: 100%; font-size: 14px; padding-right: 10px;">
                    {{tbCommunityDynamic.title}}
                    <image src="/static/icon/new.png" style="padding-left: 5px; width: 16px; height: 16px; top: 3px;"
                           v-if="!tbCommunityDynamic.isRead"></image>
                </div>
                <div style="width: 110px; color: #909399; text-align: right;">{{tbCommunityDynamic.showTime}}</div>
            </div>
        </div>

        <div style="padding-top: 10px; padding-bottom: 10px;">
            <u-loadmore :status="pagination.status" bg-color="#eeeeee"/>
        </div>

    </view>
</template>

<script>

    import {TbCommunityDynamicService} from "../../../../dev/services/tb-community-dynamic.service";
    import {CommonUtil} from "../../../../dev/core/utils/common.util";

    export default {
        data() {
            return {
                searchKeyword: '',
                tbCommunityDynamicList: []
            }
        },
        onShow() {
            const _self = this;
            this.doRefresh(this.tbCommunityDynamicList);
        },
        // 上拉加载
        onReachBottom: function () {
            if (this.pagination.hasNextPage) {
                this.doInfinite()
            }
        },
        methods: {
            onSearch(event) {
                this.searchKeyword = CommonUtil.trim(this.searchKeyword);
                this.doRefresh(this.tbCommunityDynamicList);
            },
            select(item) {
                const _self = this;
                this.objParams.navCommunityDynamicId = item.id;
                this.objParams.navCommunityDynamicTitle = item.title;
                CommonUtil.toastNavigateBack();
            },
            /**
             * 加载更多数据中
             * @param infiniteScroll
             */
            doInfinite(infiniteScroll) {
                const _self = this;
                new TbCommunityDynamicService().findTableList({
                    pagination: _self.pagination,
                    data: {
                        communityId: _self.globalVariable.userInfo.tbCommunity.id,
                        title: this.searchKeyword,
                        isPublish: true,
                        status: '1',
                        deleted: 0,
                        orderBy: 'create_time desc'
                    },
                }).then(result => {
                    _self.pagination.refreshPage(result);
                    _self.tbCommunityDynamicList = [..._self.tbCommunityDynamicList, ...result.list];
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
